package com.task.web.controller.core;

import javax.annotation.Resource;

import com.task.core.domain.AffiliateInfo;
import com.task.core.domain.MissionGroupInfo;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.task.common.annotation.Log;
import com.task.common.core.controller.BaseController;
import com.task.common.core.domain.AjaxResult;
import com.task.common.core.page.TableDataInfo;
import com.task.common.enums.BusinessType;
import com.task.common.utils.SecurityUtils;
import com.task.core.dto.request.AdvertiserRequestDTO;
import com.task.core.dto.request.MissionGroupRequestDTO;
import com.task.core.service.AdvertiserService;
import com.task.core.service.CheckService;
import com.task.core.service.MissionGroupService;

import io.swagger.annotations.Api;

/**
 * @author 迪迦.
 * @date 2024/8/14 15:09
 */
@Api("任务分组管理")
@RestController
@RequestMapping("/missionGroup")
public class MissionGroupController extends BaseController {

  @Resource
  private MissionGroupService missionGroupService;

  @Resource
  private CheckService checkService;


  @PreAuthorize("@ss.hasPermi('missionGroup:list')")
  @GetMapping("/getMissionGroupByPage")
  public TableDataInfo getMissionGroupByPage(MissionGroupRequestDTO request) {
    startPage(request.getPageNum(), request.getPageSize());
    return getDataTable(missionGroupService.getMissionGroupByPage(request));
  }


  @PreAuthorize("@ss.hasPermi('missionGroup:option')")
  @GetMapping("/getMissionGroupForOption")
  public TableDataInfo getMissionGroupForOption(MissionGroupRequestDTO request) {
    return getDataTable(missionGroupService.getMissionGroupForOption(request));
  }

  @Log(title = "任务分组管理", businessType = BusinessType.INSERT)
  @PostMapping("/addMissionGroup")
  public AjaxResult addMissionGroup(@RequestBody MissionGroupRequestDTO request) {
    missionGroupService.addMissionGroup(request);
    return success();
  }

  @Log(title = "任务分组管理", businessType = BusinessType.UPDATE)
  @PutMapping("/modifyMissionGroup")
  public AjaxResult modifyMissionGroup(@RequestBody MissionGroupRequestDTO request) {
    checkService.check("data_mission_group", request.getCode());
    missionGroupService.modifyMissionGroup(request);
    return success();
  }

  @GetMapping("/getMissionGroupByCode/{missionGroupCode}")
  @PreAuthorize("@ss.hasPermi('system:missionGroup:edit')")
  public AjaxResult getMissionGroupByCode(@PathVariable String missionGroupCode) {
    checkService.check("data_mission_group", missionGroupCode);
    MissionGroupInfo missionGroupInfo = missionGroupService.getMissionGroupByCode(missionGroupCode);
    return success(missionGroupInfo);
  }

  @Log(title = "任务分组管理", businessType = BusinessType.DELETE)
  @DeleteMapping("/deleteMissionGroup/{missionGroupCode}")
  public AjaxResult deleteMissionGroup(@PathVariable String missionGroupCode) {
    checkService.check("data_mission_group", missionGroupCode);
    missionGroupService.deleteMissionGroup(missionGroupCode, SecurityUtils.getLoginUser().getUserId());
    return success();
  }

}
